|
IntroductionNeed we say that regular expressions are a powerful, but sometimes tricky, part of TextPipe. The good news is that you don't need to be a rocket scientist to use regular expressions. The simple ones are just that -- fairly simple -- and they are all you need to understand for many applications. If you're relatively unfamiliar with regular expressions -- regexps for short -- be sure to read the section below Tips on Seat-of-the-Pants Pattern Matching. If, on the other hand, you are already comfortable using regular expressions, you won't find much of value in the Tips section, but may find subsequent tables and examples useful. Our focus is on items, like quantifiers, that you keep looking up in your reference materials because you don't use them often enough to remember the fine points. Tips on Seat-of-the-Pants Pattern MatchingThese are tips, not a tutorial. We assume you already know how to code simple substitutions with regular expressions. The irony of pattern matching with regular expressions is that although it's a highly deterministic operation, this doesn't help you much unless you are a rocket scientist. The pattern matching engine uses a complex set of rules. But, the rules are hard to understand and difficult to apply to practical problems of some complexity -- even for full-time Web page developers, much less part-timers. Fortunately, you can mostly forget about the formal matching rules and take a much more practical or seat-of-the pants approach. With this as background, here are our tips:
MetacharactersThe following characters -- so-called metacharacters -- have special meaning in regular expressions. To match them, precede them with a backslash.
Assertions identify special conditions for a pattern match. The following table covers commonly used assertions.
QuantifiersThis section complements discussions of quantifiers that are long on words but short on examples. We examine a host of variations on a basic example, using the various quantifiers in the following scenario:
We use parentheses in all examples for consistency. They only matter here when followed by a quantifier. Thus (pe)+ looks for successive occurrences of pe, whereas pe+ looks for successive occurrences of e. Substitutions shown in red merit close attention.
See also |
Contact
Us
Support
Community
Tutorials and User Guides (online) |